<div id="model-modal" style="top: 20%;" class="modal fade modal_small" role="dialog" aria-labelledby="myModalLabel1" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                <h4 class="modal-title"></h4>
            </div>
            <form action="<?php echo getUrl('member/consumer/saveAddress');?>" class="form-horizontal" id="model-form" method="post">
                <div class="modal-body">

                    <div class="form-group">
                        <label class="control-label col-md-2">收货人<span class="required">*</span></label>
                        <div class="col-md-9">
                            <input class="form-control required" name="consignee" type="text" value="">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-md-2">性别<span class="required">*</span></label>
                        <div class="col-md-9" style="margin-left: 18px;">
                            <div class="radio-list">
                                <label class="radio-inline"><input name="gender"  value="1" type="radio" > 先生 </label>
                                <label class="radio-inline" style="padding-left: 20px"><input name="gender"  value="2" type="radio"> 女士 </label>

                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-md-2">电话<span class="required">*</span></label>
                        <div class="col-md-9">
                            <input class="form-control required" name="mobile" type="text" value="">
                        </div>
                    </div>
                    <div class="form-group" id="region" data-url="<?php echo getUrl('common/ajaxChangeCheck');?>">
                        <label class="control-label col-md-2">所在区域<span class="required">*</span></label>
                        <div class="col-xs-3">
                            <select  id="province" name="province" class="form-control">
                                <option  value="">选择省份</option>
                                <?php foreach ($province as $p):  ?>
                                    <option value="<?php echo $p['id']?>"><?php echo $p['name']?></option>
                                <?php endforeach;?>
                            </select>
                        </div>
                        <div class="col-xs-3">
                            <select  id="city" name="city" class="form-control">
                                <option value="">选择城市</option>
                            </select>
                        </div>
                        <div class="col-xs-3">
                            <select id="county" name="county" class="form-control">
                                <option value="">选择区县</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-md-2">详细地址<span class="required">*</span></label>
                        <div class="col-md-9">
                            <input class="form-control required" name="address" type="text" value="" placeholder="请填写准确地址便于平台解析GPS">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-md-2">门牌号<span class="required">*</span></label>
                        <div class="col-md-9">
                            <input class="form-control required" name="street" type="text" value="">
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <input type="hidden" name="consumer_id" value="">
                    <input type="hidden" name="id" value="">
                    <button type="submit" class="btn green">保存</button>
                    <button class="btn default" data-dismiss="modal" aria-hidden="true"><i class="fa fa-times"></i> 关闭</button>

                </div>
            </form>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function(){
        var model = $('#model-modal');
        $('.add-address-btn').click(function(){
            var nickname = $('.nickname').text();
            var consumer_id = $(this).attr('consumer_id');
            model.find('.modal-title').html('新增收货地址-'+nickname);
            model.find('input[type="text"]').val('');
            model.find('input[type="radio"]').eq(0).attr("checked",'checked');
            model.find('input[name="consumer_id"]').val(consumer_id);
            model.find('input[name="id"]').val('');
            model.find("#province").find("option[value='']").attr('selected',true);
            model.find("#city").html("<option value=''>选择城市</option>");
            model.find("#county").html("<option value=''>选择区县</option>");
            model.find('.has-error').removeClass('has-error').find('.validate_message').remove();
            model.find('.show_message_error').remove();
            model.modal();

        });
        $('.edit-address-btn').live('click', function(){
            var url = $(this).attr('href');
            var nickname = $('.nickname').text();
            var consumer_id = $(this).attr('consumer_id');
            l_blockUI();
            $.ajax(url, {
                dataType:'json',
                type:'get',
                error:function(){
                    show_message({status:0, info:'请求超时'});
                    App.unblockUI();
                },
                timeout:60000,
                success:function(data,textStatus,jqXHR){
                    if(!data){
                        show_message({status:0, info:'请求超时'});
                        return;
                    }
                    model.find('input[type="radio"]').removeAttr("checked");
                    model.find('.modal-title').html('编辑收货地址  - '+nickname );
                    model.find('.has-error').removeClass('has-error').find('.validate_message').remove();
                    model.find('.show_message_error').remove();
                    for(var k in data){
                        if(k == 'province'){
                            model.find('[name="'+k+'"]').val(data[k]);
                            city(data[k], data['city']);
                        }else if(k == 'city'){
                            county(data[k], data['county']);
                        }else if(k == 'gender'){
                            var gender = data[k]-1;
                            model.find('input[type="radio"]').eq(gender).attr("checked",'checked');
                        }else{
                            model.find('[name="'+k+'"]').val(data[k]);
                        }
                    }
                    model.modal();
                    App.unblockUI();
                }
            });

            return false;
        });


        $.e_validate.init('#model-form',{modal:model,ignore:'',successCallback:function(data){
            $('#datatable_address').dataTable().fnDraw();
        }});
    });
</script>